package com.kyrioscraft.cloud.thead.jdklab.tools.simple;

/**
 * @Author kyrioscraft
 * @Date 2019/2/13 16:48
 * @Description //TODO
 **/
public class SynchronizedDemo {
    final static Object object = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (object) {
                System.out.println(System.currentTimeMillis()+" t1 start");

                try {
                    System.out.println(System.currentTimeMillis()+" t1 wait");

                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis()+" t1 end");
            }
        });

        Thread t2 = new Thread(()->{
            synchronized (object) {
                System.out.println(System.currentTimeMillis()+" t2 start, notify");
                object.notify();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis()+" t2 end");
            }
        });

        t1.start();
        t2.start();
    }
}
